package data;

import business.Accounts;

/**
 * This class manages data, methods, and fields relevant to a Scheduler.
 * This class extends User and implements Comparable.
 * 
 * @author Stephen Amos
 */
public class Scheduler extends User implements Comparable<Scheduler>{
	
	/**
	 * This constructor creates a new Scheduler object based upon the parameters
	 * passed in.
	 * 
	 * @param username The username for this Scheduler.
	 * @param password The password for this Scheduler.
	 * @param phone The phone number for this Scheduler.
	 * @param email The email address for this Scheduler.
	 */
	public Scheduler(String username, String password, String phone, String email) {
		super(username, password, phone, email);
	}
	
	/**
	 * Searches through the passed in Accounts object for a particular user
	 * based upon their username, and returns the information of that user.
	 * 
	 * @param accounts The account object to be searched through.
	 * @param username The user whose information is to be retrieved.
	 * @return The information of the requested user.
	 */
	public String viewAccount(Accounts accounts, String username) {
		User the_user = accounts.getAccount(username);
		return the_user.toString();
	}
	
	/**
	 * Sets the group leader status of the passed in Volunteer object based
	 * upon the parameter passed in.
	 * 
	 * @param user The volunteer whose group leader status is to be changed.
	 * @param leaderStatus Sets the group leader status of the passed in
	 * Volunteer.
	 */
	public void setGroupLeader(Volunteer user, boolean leaderStatus) {
		user.setLeader(leaderStatus);
	}
	
	/**
	 * Approves a job.
	 * 
	 * @param job The job whose verification status is to be approved.
	 */
	public void approveJob(Job job) {
		job.setVerified(true);
	}
	
	/**
	 * Changes a verified, scheduled job to a disabled job.
	 * 
	 * @param job The job whose status is to be disabled.
	 */
	//add this in
	public void disableJob(Job job) {
		job.setVerified(false);
	}
	
	/**
	 * Determines whether this Scheduler object is the same as another object
	 * passed in.
	 * 
	 * @param x The object to be tested for equivalency with this Scheduler.
	 * @return Returns true if, and only if this Scheduler and the object
	 * passed in are the same.
	 */
	public boolean equals(Object x) {
		if (x != null && x instanceof Scheduler && this.username != null) {
			String temp = ((Scheduler) x).getUsername();
			if (temp != null && !temp.trim().equals("") && this.username.equalsIgnoreCase(temp)) {
				return true;
			}
		}
		return false;
	}

	/**
	 * This method compares this current Scheduler object with another
	 * Scheduler object based upon the Scheduler's username.
	 * 
	 * @param other_scheduler The Scheduler object to be compared to.
	 * @return 0 if the Scheduler objects have the same username field,
	 * a negative value if the compared Scheduler is alphabetically higher,
	 * or a positive value if the compared Scheduler is alphabetically lower.
	 */
	public int compareTo(Scheduler other_scheduler) {
		return this.username.compareTo(other_scheduler.getUsername());
	}
	
	/**
	 * Returns a String containing all of a Scheduler's fields.
	 * 
	 * @return A string containing all of a Scheduler's fields.
	 */
	public String toString() {
		return username + ",," + password + ",," + phone + ",," + email + "\n";
	}

}
